/**
 * Copyright (c) [2025] [AGIROS] 
 * [travoddsgen] is licensed under Mulan PSL v2. 
 * You can use this software according to the terms and conditions of the Mulan PSL v2. 
 * You may obtain a copy of Mulan PSL v2 at: 
 *          http://license.coscl.org.cn/MulanPSL2 
 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, 
 * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, 
 * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. 
 * See the Mulan PSL v2 for more details.
 */ 

#include "FileGenVisitor.h"
#include <fstream>
#include <iostream>

FileGenVisitor::FileGenVisitor(const std::string& outputDir, const std::string& fileName)
    : outputPath_(outputDir),
     fileName_(fileName),
     indentLevel_(0),
     indent_("    ") {
}

const std::string& FileGenVisitor::getFileName() const {
    return fileName_;
}

std::string FileGenVisitor::indent() {
    std::string indentStr;
    for (unsigned int i = 0; i < indentLevel_; ++i) {
        indentStr += indent_;
    }
    return indentStr;
}

void FileGenVisitor::writeToFile() {
    if (outputPath_.empty() || fileName_.empty()) {
        return;
    }
    // 将_content写入文件
    std::ofstream file(outputPath_ + "/" + fileName_);
    if (file.is_open()) {
        file << content_;
        file.close();
    } else {
        std::cerr << "Could not open file: " << outputPath_ + "/" + fileName_ << std::endl;
    }
}